package com.mjk.dictnation;
import com.mjk.dictnation.dto.DictNationDto;
import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.base.work.BaseWork;
import com.mjk.common.core.jdbc.service.plus.wrap.BeeQueryWrapper;
import com.mjk.common.base.work.annotation.BeeWork;
import com.mjk.common.core.jdbc.service.plus.idbservice.BeeDBService;
import com.mjk.common.util.ObjectUtils;
import com.mjk.common.base.error.BeeError;
import org.springframework.beans.factory.annotation.Autowired;

@BeeWork(work = "dictnation")
public class DictNationWorkProxy extends BaseWork{
		@Autowired
		private BeeDBService baseDBService;

		/**
		 * 获取dictNation列表信息
		 * @param dto
		 * @return
		 */
		public  BeeResponse getDictNationList(DictNationDto dto){
				BeeQueryWrapper wrapper = new BeeQueryWrapper(new com.mjk.conver.NationModel());
				if(ObjectUtils.isNotEmpty(dto.getCODE())) {
						wrapper.eq(com.mjk.conver.NationModel::getCODE,dto.getCODE());
				}
				if(ObjectUtils.isNotEmpty(dto.getNAME())) {
						wrapper.eq(com.mjk.conver.NationModel::getNAME,dto.getNAME());
				}
				if(ObjectUtils.isNotEmpty(dto.getDEL_FLAG())) {
						wrapper.eq(com.mjk.conver.NationModel::getDEL_FLAG,dto.getDEL_FLAG());
				}
				if(ObjectUtils.isNotEmpty(dto.getPINYIN())) {
						wrapper.eq(com.mjk.conver.NationModel::getPINYIN,dto.getPINYIN());
				}
				if(isPage(dto)) {
						wrapper.setPage(dto.getPageStart(),dto.getPageSize());
						return BeeError.BEE_SUC.tranceError(baseDBService.findManyByWrapperWithPage(wrapper));
				}else {
						return BeeError.BEE_SUC.tranceError(baseDBService.findManyByWrapper(wrapper));
				}
		}
		/**
		 * 保存或修改dictNation
		 * @param model
		 * @return
		 */
		public  BeeResponse saveOrUpdateDictNation(com.mjk.conver.NationModel model){
				if(ObjectUtils.isNotEmpty(model.getCODE())) {
						BeeQueryWrapper wrapper = new BeeQueryWrapper(model);
						wrapper.eq(com.mjk.conver.NationModel::getCODE,model.getCODE());
						baseDBService.update(wrapper);
				}else {
						baseDBService.save(model);
				}
				return BeeError.BEE_SUC.tranceError();
		}
		/**
		 * 删除dictNation
		 * @param model
		 * @return
		 */
		public  BeeResponse delDictNation(com.mjk.conver.NationModel model){
				needParams(model, "CODE");
				BeeQueryWrapper wrapper = new BeeQueryWrapper(model);
				wrapper.eq(com.mjk.conver.NationModel::getCODE,model.getCODE());
				baseDBService.delete(wrapper);
				return BeeError.BEE_SUC.tranceError();
		}
}